#ifndef __VISION_REGISTER_H__
#define __VISION_REGISTER_H__

#include "common/status.h"

#include <map>
#include <string>
#include <functional>

namespace vision {

template <typename TYPE>
class Register {
public:

using TypeRegister = std::function<TYPE* (const std::string)>;

protected:
    static Status Registe(std::string key, TypeRegister fn)
    {
        if (m_repo.find(key) != m_repo.end()) {
            return KEY_IS_EXISTED;
        }
        m_repo[key] = fn;
        return SUCCESS;
    }

    static TypeRegister Find(std::string key)
    {
        auto it = m_repo.find(key);
        if (it != m_repo.end()) {
            return it->second;
        }
        return nullptr;
    }

public:
    static std::map<std::string, TypeRegister> m_repo;
};

// template <typename TYPE>
// std::map<std::string, Register::TypeRegister> Register<TYPE>::m_repo;
} // namespace vision

#endif // __VISION_REGISTER_H__